<?php

namespace App\Http\Controllers\Admin;



use Illuminate\Http\Request;

class UploadController extends Controller
{


    /**
     * 后台ajax图片上传，ps:待优化，图片大小，返回格式等
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function local(Request $request){

        //获取配置上传路径（含域名）
        $full_url=config('filesystems.disks.upload.url');

        $model = $request->file('imageFile');

        //判断是否为真实图片，图片文件是否存在
        if(exif_imagetype($model->getRealPath()) && $request->hasFile('imageFile') && $model){
            $saveImgPath='/apage/';
            $saveImgName=date("YmdHis").'.'.$model->getClientOriginalExtension();
            $upload = $model->storeAs($saveImgPath,$saveImgName);
            if ($upload) {
                return response()->json(['id'=>$request->get('hash'),'url'=>$full_url.$saveImgPath.$saveImgName]);
            }else{
                $message= array_values($model->errors);
                return response()->json(['error'=>true,'message'=>$message[0][0]]);
            }
        }else{
            return response()->json(['error'=>true,'message'=>'图片格式不正确']);
        }

    }
}
